package org.six11.olive3.picturephone.server.handler;

import java.util.List;

import javax.servlet.ServletException;

import org.six11.olive3.net.Message;
import org.six11.olive3.net.MessageHandler;
import org.six11.olive3.net.MessageNames;
import org.six11.olive3.picturephone.server.PPMessageNames;
import org.six11.olive3.server.DatabaseThing;
import org.six11.olive3.server.SqlStrings;
import org.six11.olive3.util.MultiState;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class DescriptionDoneMessageHandler extends MessageHandler {
  private DatabaseThing dbThing;
  private MultiState programState;
  
  public DescriptionDoneMessageHandler(DatabaseThing dbThing, MultiState programState) {
    this.dbThing = dbThing;
    this.programState = programState;
  }

  public void handleLater(Message m) {
    String userID = m.getParamValue(MessageNames.PARAM_USER_ID);
    String sketchID = m.getParamValue(PPMessageNames.PARAM_SKETCH_ID);
    String descText = m.getParamValue(PPMessageNames.PARAM_DESC_TEXT);
    try {
      dbThing.insertRow(SqlStrings.INSERT_DESCRIPTION_FOR_SKETCH, userID, sketchID, descText);
      bug("Added description for sketch " + sketchID + " by user " + userID + ": " + descText);
    } catch (ServletException ex) {
      ex.printStackTrace();
    }
  }
}
